Changing default value of an attribute

I want to change the default value of an attribute so that new objects have the new default value but withough affecting the existing objects that have the default value. Is it OK to run the following script on all objects in the database (resetting every object to it's current value) before changing the default? The attribute is defined as an enumeration of strings (SITE_A, SITE_B, BOTH, NONE, etc.). I've run a few basic tests and it seems to work...

Thanks,

               Ken.

 

Module m = current

filtering off

Object o

string current_value_of_site

for o in m do

{

current_value_of_site = o."Site"

o."Site" = current_value_of_site

}


mcnairk - Fri Nov 08 10:20:29 EST 2013

Re: Changing default value of an attribute
llandale - Fri Nov 08 10:25:10 EST 2013

Looks good.  Existing objects with a default value will have that explicit value when done.

However, this command inside the loop is better as it covers rich Text and doesn't waste string table space:

  • set(o."Site", o."Site")    // set(Attr__To, Attr__From)

-Louie

Re: Changing default value of an attribute
mcnairk - Fri Nov 08 11:16:00 EST 2013

llandale - Fri Nov 08 10:25:10 EST 2013

Looks good.  Existing objects with a default value will have that explicit value when done.

However, this command inside the loop is better as it covers rich Text and doesn't waste string table space:

  • set(o."Site", o."Site")    // set(Attr__To, Attr__From)

-Louie

Thanks! I was not aware of this version of the set command. I looked thru the DXL manual and it's not obvious...

Re: Changing default value of an attribute
llandale - Fri Nov 08 11:29:41 EST 2013

mcnairk - Fri Nov 08 11:16:00 EST 2013

Thanks! I was not aware of this version of the set command. I looked thru the DXL manual and it's not obvious...

Not in the manual...

Re: Changing default value of an attribute
llandale - Fri Nov 08 11:43:05 EST 2013

Default/Inherited discussion.  When an obj-attr value is null then it can APPEAR to have a Default or Inherited value; I think Inherited has precedence over Default.  "Appear" means:

  • You can see it in the GUI
  • string s = o.NameAttr indeed retrieves the Defaulted/Inherited value

So if the Default value is "Hello" and you see "Hello", you don't know if that value is defaulted to "Hello" or it is set explicitely to "Hello"; but usually you do not care.  If you need to know, there is a command for that:

  • bool     hasSpecificValue(Object,AttrDef)

which unfortunately forces you to get an AttrDef handle before you can query:

  • AttrDef ad = find(m, NameAttr)
  • bool Inherits = ad.inherit
  • bool HasDefault = (bool ad.defval)   // this "defval" means "has a default value" ...
  • string DefValue = (string ad.defval)  // ... not the same as this "defval", which means "This is the default value"
  • for o in m do
  • {   if (hasSpecificValue(o, ad))    //
  •      then print identifier(o) "\t" NameAttr "\t[" (o.NameAttr) "]\tIs Specific\n"
  •      else print identifier(o) "\t" NameAttr "\tI" (o.NameAttr) "]\ts Blank/Inherited/Defaulted\n"
  • }

-Louie